package com.tianji.remark.task;

import com.tianji.remark.service.ILikedRecordService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.List;


@Slf4j
@Component
@RefreshScope
@RequiredArgsConstructor
public class LikeTimesCheckTask {
    private final ILikedRecordService likedRecordService;
    private final List<String> BIZ_TYPE = List.of("QA", "NOTE");
    private Integer maxBizSize = 20;

    /**
     * 定时任务 -- 检测点赞次数，并发送业务方持久化（day06-随堂-03）
     */
    @Scheduled(fixedDelay = 20*1000)
    public void checkLikes(){
        log.warn("检测点赞次数，并将点赞次数持久化。当前任务处理数：{}",maxBizSize);
        for (String bizType : BIZ_TYPE) {
            likedRecordService.readLikedTimesAndSendMessage(bizType, maxBizSize);
        }
    }

}
